/*
 * @Description: 
 * @Autor: starzhou
 * @Date: 2020-08-31 20:34:35
 * @LastEditTime: 2020-09-09 18:57:17
 */
const CompressionWebpackPlugin = require('compression-webpack-plugin')

const compress = new CompressionWebpackPlugin(
  {
    filename: info => {
      return `${info.path}.gz${info.query}`
    },
    algorithm: 'gzip',
    threshold: 10240,
    test:/\.js$|\.html$|.\css/,
    minRatio: 0.8,
    deleteOriginalAssets: false
  }
)
module.exports = {
  outputDir: 'docs',
  publicPath: '/',
  assetsDir: 'static',
  productionSourceMap: false,
  devServer: {
    proxy: process.env.NODE_ENV === 'production'
      ? {}
      : {
        '': {
          target: 'https://wechat-qafc.xjfsaas.com/',
          changeOrigin: true
        }
      }
  },
  chainWebpack: config => {
    //最小化代码
    config.optimization.minimize(true);
    //分割代码
    config.optimization.splitChunks({
      chunks: 'all'
    });
    // //压缩图片
    config.module
      .rule('images')
      .use('image-webpack-loader')
      .loader('image-webpack-loader')
      .options({
        bypassOnDebug: true
      })
      .end()
  },
  configureWebpack: {
    plugins: [compress],
    externals: {
      'element-ui': 'ELEMENT',
      'echarts': 'echarts',
      'vue': 'Vue',
   }
  }
}